
import matplotlib.pyplot as plt
import numpy as np

# bar()方法绘制柱形图
def fun1():
    x = np.array(['Java', 'Python', 'C++', 'JavaScript'])
    y = np.array([12, 22, 6, 18])

    plt.bar(x, y)
    plt.show()

# barh()方法绘制垂直方向的柱形图
def fun2():
    x = np.array(['Java', 'Python', 'C++', 'JavaScript'])
    y = np.array([12, 22, 6, 18])

    plt.barh(x, y)
    plt.show()

# 设置柱形图颜色
def fun3():
    x = np.array(['Java', 'Python', 'C++', 'JavaScript'])
    y = np.array([12, 22, 6, 18])

    plt.bar(x, y, color='#4CAF50')
    plt.show()

# 自定义各个柱形的颜色
def fun4():
    x = np.array(['Java', 'Python', 'C++', 'JavaScript'])
    y = np.array([12, 22, 6, 18])

    plt.bar(x, y, color=['#4CAF50', 'red', 'hotpink', '#555B2F'])
    plt.show()

# 设置柱形图宽度，bar()方法使用width，barch()方法使用height
def fun5():
    x = np.array(['Java', 'Python', 'C++', 'JavaScript'])
    y = np.array([12, 22, 6, 18])

    # plt.bar(x, y, width=0.1)
    plt.barh(x, y, height=0.1)
    plt.show()

if __name__ == '__main__':
    fun5()